package com.ptu.spzx.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ptu.spzx.common.exception.ptuException;
import com.ptu.spzx.model.entity.system.SysCourseUser;
import com.ptu.spzx.model.vo.common.ResultCodeEnum;
import com.ptu.spzx.user.mapper.CourseUserMapper;
import com.ptu.spzx.user.service.CourseUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseUserServiceImpl extends ServiceImpl<CourseUserMapper, SysCourseUser> implements CourseUserService {
    @Autowired
    private CourseUserMapper courseUserMapper;
    @Override
    public void addCourseUser(List<Long> teachIds, Long courseId) {
        if(teachIds==null|| courseId==null){
            throw new ptuException(ResultCodeEnum.PARAM_NULL);
        }
        for(Long teachId:teachIds){
            SysCourseUser sysCourseUser=new SysCourseUser();
            sysCourseUser.setUserId(teachId);
            sysCourseUser.setBelongCourseId(courseId);
            courseUserMapper.addCourse(sysCourseUser);
        }
    }

    @Override
    public void deleteCourseUser(Long curseId) {
        courseUserMapper.deleteCourseUser(curseId);
    }

    @Override
    public List<Long> selectCourseIdByteachId(Long teachId) {
        List<Long> courseId = courseUserMapper.selectCourseIdByteachId(teachId);
        return courseId;
    }

    @Override
    public List<Long> selectTeacherIdByCourseId(Long courseId) {
        List<Long> teachIds = courseUserMapper.selectTeacherIdByCourseId(courseId);
        return teachIds;
    }
}
